/*
 * @lc app=leetcode.cn id=155 lang=golang
 *
 * [155] 最小栈
 */

// @lc code=start
package main

type MinStack struct {
	queue    *Stack
	min      *Stack
	capcatiy int
}

type Stack struct {
	val  int
	next *Stack
}

/** initialize your data structure here. */
func Constructor() MinStack {
	return MinStack{&Stack{}, &Stack{}, 0}
}

func (this *MinStack) Push(val int) {
	if this.capcatiy == 0 {
		this.min.next = &Stack{val: val}
		this.queue.next = &Stack{val: val}
		this.capcatiy++
	} else {
		this.capcatiy++
		v := &Stack{val: val}
		minVal := this.min.next.val
		minT := &Stack{}
		if minVal < val {
			minT.val = minVal
		} else {
			minT.val = val
		}
		this.min.next, minT.next = minT, this.min.next
		this.queue.next, v.next = v, this.queue.next
	}
}

func (this *MinStack) Pop() {
	if this.capcatiy <= 0 {
		return
	}
	this.capcatiy--
	this.queue.next = this.queue.next.next
	this.min.next = this.min.next.next
}

func (this *MinStack) Top() int {
	if this.capcatiy <= 0 {
		return -1
	}
	return this.queue.next.val
}

func (this *MinStack) GetMin() int {
	if this.capcatiy <= 0 {
		return -1
	}
	return this.min.next.val
}

/**
 * Your MinStack object will be instantiated and called as such:
 * obj := Constructor();
 * obj.Push(val);
 * obj.Pop();
 * param_3 := obj.Top();
 * param_4 := obj.GetMin();
 */
// @lc code=end
